/*
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-07 21:12:14
 * @LastEditors: renmengxue
 * @LastEditTime: 2023-12-07 21:37:45
 */
import { useStore } from 'vuex'
import { ref, computed, ComputedRef } from 'vue'
interface LoadMoreParams {
  currentPage:number,
  pageSize:number,
}
const useLoadMore = (actionName:string, total:ComputedRef<number>, params:LoadMoreParams = {
  currentPage: 2,
  pageSize: 5
}) => {
  const store = useStore()// 创建仓库
  const currentPage = ref(params.currentPage)// 默认的ref的当前页
  const requestParams = computed(() => ({
    currentPage: currentPage.value,
    pageSize: params.pageSize
  }))
  const loadMorePage = () => store.dispatch(actionName, requestParams.value).then(() => {
    currentPage.value = currentPage.value + 1
  }
  )
  // 判断是不是最后一页
  const lastPage = computed(() => {
    // 1.2 结果是2
    return Math.ceil(total.value / params.pageSize) < currentPage.value
  })
console.log(123)

  return {
    loadMorePage,
    lastPage
  }
}

export default useLoadMore
